package com.wlz.rocketmq.batchmessage;

import com.wlz.rocketmq.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 *  批量消息 -- 生成者 (简单模式)
 *
 *   一次批量消息 不能 超过  1MB ,最大 4MB
 *   不能是 延迟消息，事务消息
 * @author wlz
 * @date 2022-07-02  3:26 下午
 */
@Slf4j
public class SimpleBatchProducer {

    public static void main(String[] args) throws Exception{

        DefaultMQProducer producer = new DefaultMQProducer("batch_producer_group_name");

        producer.setNamesrvAddr(Constants.NAMESVADDR);

        producer.start();
        String topic = "BatchTopic";

        List<Message> messages = new ArrayList<>();
        messages.add(new Message(topic, "Tag", "orderID001", "helloworld 1".getBytes()));
        messages.add(new Message(topic, "Tag", "orderID002", "helloworld 2".getBytes()));
        messages.add(new Message(topic, "Tag", "orderID003", "helloworld 3".getBytes()));
        messages.add(new Message(topic, "Tag", "orderID004", "helloworld 4".getBytes()));

        producer.send(messages);

        producer.shutdown();


    }
}
